/**
 * Created by CK on 2016/6/24.
 */
$(document).ready(function(){
    var schoolId  = xhTool.getQuery('iSchoolId');
    var DataGrid2 = new DataGridEvent();
    var appList     = $('#SchoolOutAppList');
    var versionList = $('#SchoolAppVersionList');
    var btnModal    = $(window.top.document).find('#bt_modal_confirm');
    appList.initDataGrid('getAppDgData', {"queryParams": {"iSchoolId": schoolId, "type": "out"}});
    //应用列表加载后刷新版本列表
    DataGrid.onLoadSuccess = function(data){
        appList.datagrid('selectRow', 0);
        versionList.initDataGrid('getAppDgData', {"queryParams": {"type": "version", "iAppCode":data["rows"][0].iAppCode}}, DataGrid2);
        btnModal.addClass('disabled');
    };
    //点击应用列表加载版本列表
    DataGrid.onClickRow = function(rowIndex, rowData){
        //添加参数
        versionList.addDataGridParams({"type": "version", "iAppCode":rowData.iAppCode});
        btnModal.addClass('disabled');
    };
    DataGrid2.onClickRow = function(rowIndex, rowData){
        btnModal.removeClass('disabled');
    };
    btnModal.click(function(){
        var appId = versionList.getDataGridSelectedField('iAppId');
        $.post('contactSchoolApp', {iAppId: appId, iSchoolId: schoolId}, function(result){
            if(result != 1) return false;
            window.top.xhTop.getActiveFrame().$('#List').dataGridReload();
            window.top.xhTop.closeModal();
            //$(window.top.document).find('#bt_modal_close').click();
        });
    });
});